package project.active;

import java.util.ArrayList;
import java.util.List;

import model.pojo.Employee;

import project.adapter.ProjectMemberTesterAdapter;
import project.dao.PrCompositionDAO;
import project.model.PrComposition;
import project.model.PrProject;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ListView;
import android.widget.TextView;
import approve.action.R;

public class ListMemberProject extends Activity{
	ListView listprojectMember;
	private String lang="EN",database="admin";
	TextView currentMemberProject,lbLstMember;
	TextView logout,username;
	private Employee emp=new Employee();
	Bundle language;

	public String getDatabase() {
		Bundle extras = getIntent().getExtras();
		if (extras != null) {
			database = extras.getString("database");
		}
		return database;
	}
	public String getLang(){
    	Bundle extras = getIntent().getExtras();
    	if(extras != null){
    		lang = extras.getString("lang");
    	}
    	return lang;
    }
    
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(approve.action.R.layout.lstmemberproject);
		language = getIntent().getExtras().getBundle(getLang());
		
		currentMemberProject = (TextView)findViewById(R.id.nameproject);
		listprojectMember =(ListView)findViewById(R.id.listMember);
		lbLstMember = (TextView)findViewById(R.id.lb_lstMember);
		
		
		Intent intent = this.getIntent();
		PrProject prProject = (PrProject)intent.getSerializableExtra("prproject");
		emp = (Employee)intent.getSerializableExtra("emp");
		currentMemberProject.setText(prProject.getNameProject());
		
		ProjectMemberTesterAdapter pm = new ProjectMemberTesterAdapter(this, loadMemberByIDProject(prProject.getIdProject()));
		listprojectMember.setAdapter(pm);
//		listprojectMember.setAdapter(new ArrayAdapter<PrComposition>(this, android.R.layout.simple_list_item_1, loadMemberByIDProject(prProject.getIdProject(),getDatabase())));
		
		logout=(TextView)findViewById(R.id.logout);
		username=(TextView)findViewById(R.id.username);
		
		logout.setOnClickListener(listenerLogout);
		username.setText(emp.getUserName());
		logout.setText(language.getString("Logout"));
		
		lbLstMember.setText(language.getString("lstmember"));

//		report=(TextView)findViewById(R.id.report);report.setText("22");
	}
	
	
	// load member
	private List<PrComposition> loadMemberByIDProject(String idProject){
		List<PrComposition> lst = new ArrayList<PrComposition>();
		lst = PrCompositionDAO.getMemberProjectByID(idProject,getDatabase());
		return lst;
	}
	
	private OnClickListener listenerLogout=new OnClickListener() {
		
		public void onClick(View v) {
			// TODO Auto-generated method stub
			Intent i=new Intent(ListMemberProject.this, LogoutActivity.class);
			i.putExtra("database", getDatabase());
			startActivity(i);
		}
	};
	
}
